<script type="text/javascript">
var timeOutObj = null;
var address_type = 0;
function getArea(level,sqlTable,type)
{
	$('#myModal').modal('show');
	if(type != undefined){
		address_type = type;
		if(address_type == 'post_address'){
			$('.my_address_name').hide();
			$('#post_address_street').show();
			if($('input[name=post_street]').length > 0){
				$('.address_info_city').children('span').eq(0).html($('input[name=post_province]').attr('area_name')).attr('area_id',$('input[name=post_province]').val());
				$('.address_info_city').children('span').eq(1).html($('input[name=post_city]').attr('area_name')).attr('area_id',$('input[name=post_city]').val());
				$('.address_info_city').children('span').eq(2).html($('input[name=post_area]').attr('area_name')).attr('area_id',$('input[name=post_area]').val());
				$('.address_info textarea').val($('input[name=post_street]').val());
			}else{
				$('.address_info_city').children('span').html('未选择').removeAttr('area_id');
				$('.address_info textarea').val('输入具体地址，详细到门牌号');
			}
		}else if(address_type == 'my_address'){
			$('.my_address_name').show();
			$('#post_address_street').hide();
			$('.address_info_city').children('span').html('未选择').removeAttr('area_id');
			$('.address_info textarea').val('输入具体地址，详细到门牌号');
		}
	}4115.23/411.65
	$('.select_box_select').hide();
	$('.select_box_loding').fadeIn('fast',function(){
		var bgDom = '';
		if(sqlTable != 'province'){
			if($('.select_box_select ul').attr('level_type') == 'area'){
				bgDom = '<li onclick="setArea(this,\'back\')" area_type="province" area_id="0">返回上一级</li>';
				}else{
					bgDom = '<li onclick="setArea(this,\'back\')" area_type="'+$('.select_box_select ul').attr('level_type')+'" area_id="'+$('.select_box_select ul').attr('level_parent')+'">返回上一级</li>';
					}
			};
		$('.select_box_select ul').html(bgDom).attr({'level_parent':level,'level_type':sqlTable});
		$.post('<?php echo site_url('common/getArea'); ?>',{'fatherId':level,'sqlTable':sqlTable},function(data)
			{
			$.each(data,function(i,j){
				$('.select_box_select ul').append('<li onclick="setArea(this,\'\')" area_type="'+sqlTable+'" area_id="'+j[sqlTable+'ID']+'">'+j[sqlTable]+'</li>');
				});
			$('.select_box_loding').hide();
			$('.select_box_select').fadeIn();
			},'json');
	});
}
function setArea(target,type)
{
	var next_type = '';
	var area_type = $(target).attr('area_type');
	var area_id = $(target).attr('area_id');
	var area_name = $(target).html();
	if(type == 'back'){
		getArea(area_id,area_type);
		return;
	}
	if(area_type == 'province'){
		$('.address_info_city').children('span').html('未选择');
		var n = 0;
		next_type = 'city';
	}else if(area_type == 'city'){
		var n = 1;
		next_type = 'area';
	}else if(area_type == 'area'){
		var n = 2;
	}
	$('.address_info_city').children('span').eq(n).html(area_name);
	$('.address_info_city').children('span').eq(n).attr('area_id',area_id);
	if(area_type == 'area')
	{
		$(target).siblings().removeAttr('style');
		$(target).css({'background-color':'#666','color':'#fff'})
	}
	else
	{
		getArea(area_id,next_type);
	}
}
function edit_address()
{
	var isEmpty = 0;
	var address_str = '';
	$.each($('.address_info_city span'),function(i,j){
		if($(j).html() != '未选择'){
			address_str+=$(j).html()+' ';
			}else{
				isEmpty = 1;
				}
		});
	if(isEmpty == 1){
		$('.modal-body').prepend('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button><strong>提示!</strong>  请选择正确的省、市、区.</div>');
	}
	if(address_type == 'post_address'){
		if($('.address_info textarea').val() == '输入具体地址，详细到门牌号'){
			isEmpty = 1;
			$('.modal-body').prepend('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button><strong>提示!</strong>  请输入详细地址，具体到街道、门牌号.</div>');
		}else{
			address_str += $('.address_info textarea').val();
		}
	}else if(address_type == 'my_address'){
		if($('#my_address_name').val() == ''){
			isEmpty = 1;
			$('.modal-body').prepend('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button><strong>提示!</strong>  发货人姓名不能为空.</div>');
		}
	}
	timeOutObj = setTimeout(removeAlert,2000);
	if(isEmpty == 0){
		if(address_type == 'post_address'){
			$('input[name=post_address]').val(address_str);
			$('input[name=post_address]').siblings().remove();
			$.each($('.address_info_city span'),function(i,j){
				$('input[name=post_address]').after('<input type="hidden" area_name="'+$(j).html()+'" name="post_'+$(j).attr('area_type')+'" value="'+$(j).attr('area_id')+'" />');
			});
			$('input[name=post_address]').after('<input type="hidden" name="post_street" value="'+$('.address_info textarea').val()+'"/>');
			$('#myModal').modal('hide');
		}else if(address_type == 'my_address'){
			$('input[name=my_address_type]').last().parents('label').before('<label class="radio"><input type="radio" value="0" name="my_address_type" checked="checked"/>'+$('#my_address_name').val()+','+address_str+'　　 <a href="javascript:void(0);" onclick="deleteMyAddress(this)">删除</a></label>');
			$('input[name=my_address_type]').last().parents('label').siblings('input').remove();
			var address_info = '';
			$.each($('.address_info_city span'),function(i,j){
				address_info += '  '+$(j).html();
				$('input[name=my_address_type]').last().parents('label').after('<input type="hidden" area_name="'+$(j).html()+'" name="my_'+$(j).attr('area_type')+'" value="'+$(j).attr('area_id')+'" />');
			});
			$('input[name=my_address_type]').last().parents('label').after('<input type="hidden" name="my_address" value="'+address_info+'"/><input type="hidden" name="my_name" value="'+$('#my_address_name').val()+'"/>').hide();
			$('#myModal').modal('hide');
		}
	}
}
function removeAlert(){
	clearTimeout(timeOutObj);
	$('.alert').last().fadeOut('slow',function(){
		if($('.alert').length > 0){
			timeOutObj = setTimeout(removeAlert,2000);
		}
		$(this).remove();
	});
}
function deleteMyAddress(target){
	if($(target).siblings('input').val() == 0){
		$(target).parents('label').remove();
		$('input[name=my_address_type]').last().parents('label').siblings('input').remove();
		$('input[name=my_address_type]').last().parents('label').show();
	}
}
</script>
<div class="modal hide fade in" id="myModal" style="top: 50%;">
<style>
.select_box{width: 200px;height: 100px;float: left;border: 1px #ccc solid;}
.select_box_select{height: 100px;overflow-y: scroll;overflow-x: hidden;display: none;}
.select_box_select ul{padding: 0px;margin: 0px;list-style: none;}
.select_box_select ul li{line-height: 25px;padding: 0px 20px;cursor: pointer;margin: 0px 5px;}
.select_box_select ul li:hover{background-color: rgb(102, 102, 102);color: rgb(255, 255, 255);}
.select_box_loding{width: 200px;height: 100px;background: url(img/loading_s.gif) no-repeat 85px 35px;display: none;}
.address_info{width: 270px;height: 90px;float: left;border: 1px #ccc solid;margin-left: 15px;padding: 5px 20px;}
.address_info_city{padding: 5px 10px;}
.address_info_city span{line-height: 25px;padding-right: 10px;}
.address_info textarea{width: 260px;height: 45px;margin-bottom: 0;}
.my_address_name{float: left;padding-top: 15px;}
.my_address_name label{float: left;line-height: 25px;}
</style>
   <div class="modal-header">
       <button type="button" class="close" data-dismiss="modal">×</button>
       <h3>选择收货地址</h3>
   </div>
   <div class="modal-body">
      <div class="select_box">
      	<div class="select_box_select">
      		<ul level_type="province" level_parent="0">
      		</ul>
      	</div>
      	<div class="select_box_loding"></div>
      </div>
      <div class="address_info">
      	<div class="address_info_city">
      		<h5 style="float: left;line-height: 24px;">地址：</h5><span area_type="province">未选择</span><span area_type="city">未选择</span><span area_type="area">未选择</span>
      	</div>
      	<textarea id="post_address_street" onfocus="if(this.value=='输入具体地址，详细到门牌号'){this.value='';}" onblur="if(this.value==''){this.value='输入具体地址，详细到门牌号';}">输入具体地址，详细到门牌号</textarea>
      	<div class="my_address_name">
          <label for="my_address_name">发货人姓名：</label>
          <input type="text" class="input-xlarge" id="my_address_name" style="width: 150px;">
      	</div>
      </div>
   </div>
   <div class="modal-footer">
      <a href="#" class="btn" data-dismiss="modal">关闭</a>
      <a href="javascript:void(0);" onclick="edit_address();" class="btn btn-primary">确认收货地址</a>
   </div>
</div>

<div class="span10">
          <div class="row-fluid">
            <div class="span12 box">
            <?php echo (isset($tips))?$tips:'';?>
                <div class="box-head">
                    <h3><i class="icon-white icon-list-alt" style="margin-top: 7px;"></i> 提交订单</h3>
                </div>
                <div class="box-content">
                    <div class="content-inner">
                        <div class="content-settings">
                            <div class="tabbable"> <!-- Only required for left/right tabs -->
                              <ul class="nav nav-tabs">
                                <li class="active" id="formorder_tab"><a href="#formorder" data-toggle="tab">表单提交</a></li>
                                <li id="formorder_tab"><a href="#fileorder" data-toggle="tab">批量提交</a></li>
                              </ul>
                              <div class="tab-content">
                                   <div class="tab-pane active" id="formorder"><!-- formorder -->
                                        <div class="row-fluid">
                                            <div class="span10">
                                                <form name="profile" onSubmit="return formVerific()" class="form-horizontal" action="<?php echo site_url('member/order_center/doAdd'); ?>" enctype="multipart/form-data"  method="post">
                                                    <fieldset>
                                                    <div class="control-group">
                                                      <label class="control-label" style="color:red;">当前价格</label>
                                                      <div class="controls">
                                                      	<input type="hidden" value="0" name="shop_type" />
                                                      	<input type="hidden" value="<?php echo $siteGlobals['prince'][0];?>" name="prince" />
                                                        <input class="input-xlarge disabled" id="disabledInput" type="text" placeholder="￥<?php echo $siteGlobals['prince'][0];?>" disabled="">
                                                      </div>
                                                    </div>
                                                    <div class="control-group">
                                                      <label class="control-label">收货地址</label>
                                                      <div class="controls">
                                                        <input onclick="getArea(0,'province','post_address');" type="text" class="input-xlarge" name="post_address" value="请选择">
                                                      </div>
                                                    </div>
                                                    <div class="control-group">
                                                      <label class="control-label">　收货人</label>
                                                      <div class="controls">
                                                        <input type="text" name="post_name" class="input-xlarge" value="">
                                                      </div>
                                                    </div>
                                                    <div class="control-group">
                                                      <label class="control-label">联系方式</label>
                                                      <div class="controls">
                                                        <input type="text" class="input-xlarge" name="post_tel" value="">
                                                      </div>
                                                    </div>
                                                    <div class="control-group">
                                                      <label class="control-label">发货地址</label>
                                                      <div class="controls">
                                                      	<?php foreach ($myAddressData as $k=>$v):;?>
                                                        <label class="radio"><input type="radio" name="my_address_type" value="<?php echo $v['id'];?>" is_auto="<?php echo $v['is_auto'];?>" <?php echo ($v['is_auto'] == 1)?'checked':'';?> /><?php echo $v['name'].' , '.$v['address_info'];?>　　<a href="<?php echo site_url('member/member_center/myAddress'); ?>">编辑</a> | <a href="<?php echo site_url('member/member_center/myAddress'); ?>">删除</a> | <?php echo ($v['is_auto'] == 1)?'当前默认':'<a href="'.site_url('member/member_center/myAddress').'">设置默认</a>';?></label>
                                                        <?php endforeach;?>
                                                        <label class="radio" onclick="getArea(0,'province','my_address');"><input type="radio" name="my_address_type" value="on" />使用新地址</label>
                                                      </div>
                                                    </div>
                                                    <div class="form-actions">
                                                       <input type="submit" value="提交订单" class="btn" <?php echo ($post_number==0)?'disabled':'';?> />
                                                       <span style="color: red;margin-top: 10px;font-size: 12px;">库存（<?php echo $post_number;?>）</span>
                                                    </div>
                                                    </fieldset>
                                                </form>
                                            </div>
                                          </div>
                                        </div> <!-- formorder -->
                                        <script type="text/javascript">
                                        function formVerific()
                                        {
                                            var post_address = $('input[name=post_address]').val();
                                            var post_name = $('input[name=post_name]').val();
                                            var post_tel = $('input[name=post_tel]').val();
                                            var myAddress = $('input[name=my_address_type]:checked').val();
                                            if(post_address == '' || post_address == '请选择')
                                            {
                                            	$('input[name=post_address]').siblings('span').remove();
                                            	$('input[name=post_address]').after('<span class="help-inline">*选择快件的收货地址.</span>').parents('div[class=control-group]').addClass('error').click(function()
                                                    	{
                                            		$('input[name=post_address]').siblings('span').remove();
                                            		$('input[name=post_address]').parents('div[class=control-group error]').removeClass('error');
                                                    	});
                                            }
                                            if(post_name == ''){
                                            	$('input[name=post_name]').siblings().remove();
                                            	$('input[name=post_name]').after('<span class="help-inline">*必须填写快件的收货人姓名.</span>').parents('div[class=control-group]').addClass('error').click(function()
                                                    	{
                                            		$('input[name=post_name]').siblings().remove();
                                            		$('input[name=post_name]').parents('div[class=control-group error]').removeClass('error');
                                                    	});
                                            }
                                            if(post_tel == ''){
                                            	$('input[name=post_tel]').siblings().remove();
                                            	$('input[name=post_tel]').after('<span class="help-inline">*快件的收货人联系方式是必须的.</span>').parents('div[class=control-group]').addClass('error').click(function()
                                                    	{
                                            		$('input[name=post_tel]').siblings().remove();
                                            		$('input[name=post_tel]').parents('div[class=control-group error]').removeClass('error');
                                                    	});
                                            }
                                            if(myAddress == 'on'){
                                                $('input[name=my_address_type]').eq(0).attr('checked',true);
                                            }
                                            if(post_address == '' || post_address == '请选择' || post_name == '' || post_tel == ''){
                                                return false;
                                            }else{
                                                return true;
                                            }
                                        }
                                        </script>
                                        <div class="tab-pane" id="fileorder"><!-- fileorder -->
                                        	<div class="well">
                                        		<blockquote>
                                        		<h4>特别说明:</h4>
                                        		<h5 style="font-weight: normal;line-height: 30px;">选择本机中制作好的表格（.xls或.xlsx）文件且注意表格的<abbr title="程序可以读取的表格样式">固定样式</abbr>。<a href="<?php echo site_url('common/doDownload?file=excel/templet.xls')?>">下载表格模板(固定样式)</a></h5>
                                        		<small>系统不会自动判断表格内字段的完整性,如果不按照格式制作表格，将会导至信息出错！！！</small>
				                        		</blockquote>
				                        	</div>
                                          <form name="fileorder" class="form-horizontal" enctype="multipart/form-data" action="<?php echo site_url('member/order_center/doAdd'); ?>"  method="post">
                                            <div class="control-group">
                                                <label class="control-label">选择上传文件</label>
                                                <div class="controls">
                                                   <input type="file" name="userfile" />
                                                </div>
                                            </div>
                                            <div class="control-group">
                                              <label class="control-label">输入安全码确认</label>
                                              <div class="controls">
                                                <input type="password" class="input-xlarge" name="tradecode">
                                              </div>
                                            </div>
                                            <div class="form-actions">
                                                <input type="submit" name="submit" value="提交" class="btn" />
                                            </div>
                                          </form>
                                        </div> <!-- fileorder -->
                                </div><!-- tab-content-->
                           </div> <!-- end tabbable -->
                        </div>
                    </div><!-- content-inner -->
                </div>
            </div>
          </div> <!-- end row -->
        </div><!--/span-->
      </div><!--/row-->